/*
 * OurShell.h
 *
 *  Created on: Jul 12, 2009
 *      Author: elkobir
 */

#ifndef OURSHELL_H_
#define OURSHELL_H_

#include <vector>
#include "Process.h"
#include "Library.h"

using namespace std;

class OurShell {

private:
	vector<int>* _processTable; // need to be other type ?? or more data in this class
	int _currProcessIndex;
	int _currProcessID;
	string _currPath;

	int contextSwitch(int processID);
	int getIndexByID(int processID);
	string getPath(int processID);
	string printPrompt();
	// for command like switch process create process...
	bool isShellJob(string command);

public:
	OurShell();
	virtual ~OurShell();

	void runShell();

		// Switches to the context of a different process.
		// Make sure to also switch to the new process' fd table and working directory.
		int swprc(int new_process_num);

		// Creates a process with the given id. If a process with this id already exists,
		// return an error. If parent == -1, this process is created with no open files.
		// If parent > -1, this process is defined as the child of the process with id parent.
		// This means that it is created with an exact copy of the fd table of the parent.
		// If process with id parent doesn’t exist return an error.
		// This function doesn’t switch to the context of the newly created process,
		// rather it stays in the context of the current process.
		int crprc(int id ,int parent);

		// This function is needed to test the file system intensively.
		// It allows executing many commands quickly from a file given as input.
		// Do not wait for a command to return before dispatching the next command.
		// For example, if requested to read a large amount of data, the shell should
		// be able to receive another command even though the read command hasn't finished yet.
		// Each command has the following syntax:
		// [commandName][space][first arg][space][second arg] etc.
		// Each space will be exactly one space. Each command is terminated by a '\n'.
		void batch(string file_name);

};

#endif /* OURSHELL_H_ */
